<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.hz.util.ParamUtil"%>
<%@page import="com.hz.control.UserControl"%>
<%@page import="com.hz.model.User"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>用户登入</title>
	</head>
	<body>
<%
    
	String rand = (String) session.getAttribute("rand");
	session.removeAttribute("rand");
	String input = request.getParameter("rand");
	//System.out.print(input);
	//System.out.print(rand);
	if(input==null||!input.equals(rand)){
	     %>
	     <script type="text/javascript">
	     alert("验证码错误");
	     history.go(-1);
	     </script>
	     <%
	}
	else{
	String username = request.getParameter("username");
	String pwd =  request.getParameter("password");
	System.out.print(UserControl.isUser(username, pwd));
	 //if(rand.equals(input)){
	if(session.getAttribute("user")!=null){
	%>
	<script>
	      alert("你尚未退出，若要重新登陆请先退出已登陆账号");
	      if(window.confirm("是否退出已登陆账号？")){
	          window.location.href="logout.jsp";
	      }else{
	          window.location="session_check.jsp";
	      }
	</script>
	<%}else{
	   if (UserControl.isUser(username, pwd)!=0) {
	        int uid = UserControl.isUser(username, pwd);
			session.setAttribute("userid",uid); 
			User  u =UserControl.getUserInformation(uid);
			session.setAttribute("user",u); 
			if(u.getRole()==0)
			response.sendRedirect("../../volunteer/pages/user.jsp");
			if(u.getRole()==1)
			response.sendRedirect("../../volunteer/pages/admin.jsp");
		} else {
%>
	<script type="text/javascript">
		alert("用户名或密码错误,请重新输入！");
		history.go(-1);
	</script>
<% }}}
%>

	</body>
</html>
